#pragma once
#include <string>
#include <vector>
#include <exception>

class SimpleCSV {
public:
  SimpleCSV() {
    delim_ = ',';
  }

  SimpleCSV(std::string str) {
    delim_ = ',';
    str_ = str;
    Parse();
  }

  void Parse() {
    Explode(std::string(str_));
  }

  std::string operator[](int i) {
    //return std::string();
    try {
    return csv_.at(i);
    } catch(std::out_of_range& e) {
      e;
      //std::cout << e.what();
      return std::string();
    }
  }

private:
  void Explode(std::string& str) {
    size_t n = str.find_first_of(delim_);
    csv_.push_back(str.substr(0, n));
    str.erase(0, n+1);
    if (!str.empty() && n != std::string::npos) {
      Explode(str);
    }
  }

  std::string str_;
  std::vector<std::string> csv_;
  char delim_;
};